<template>
	<view class="box">


	<view class="top">
			<u-field
					v-model="mobile"
					label="手机号"
					placeholder="请输入手机号"
				maxlength="11"
				>
				</u-field>
		<u-field
			v-model="sms"
			label="验证码"
			placeholder="请输入验证码" 
			maxlength="6"
		>
			<u-button size="mini" slot="right" type="primary" @click="getCode">{{codeText}}</u-button>
		</u-field>
		<u-verification-code ref="uCode" @change="codeChange"></u-verification-code>
	
					
					<u-button type="primary" class="m_t_18" @click="login">登录</u-button>
			</view>
		
	</view>
</template>

<script>
	import {
		xcxPayTest,
		send,
		check,
		getXcxurl,
		tj
	} from '../../api/index.js'
	export default {
		data() {
			return {
			mobile:'',
			sms:"",
			codeText: '获取验证码'

			}
		},
		components: {

		},
		methods: {
			login(){
				if(this.sms==''){
				wx.showToast({
					title: '验证码为空',
					icon: 'none'
				});	
				}else{
				check({
					  mobile:this.mobile,
					        event:"login",
					        captcha:this.sms,
					        type:'3'
				}).then((res)=>{
					uni.setStorageSync('phone', this.mobile)
					  wx.navigateTo({
					    url: `plugin://kdPlugin/index?pt=923091401&phone=`+this.mobile+`&env=master`
					  })
				})	
				}
		
			},
	codeChange(text) {
					this.codeText = text;
				},
				getCode() {
					if (!/^1[3456789]\d{9}$/.test(this.mobile)) {
						// 手机号格式不正确，提示用户
						wx.showToast({
							title: '请输入正确的手机号',
							icon: 'none'
						});
					}else{
						if(this.$refs.uCode.canGetCode) {
							// 模拟向后端请求验证码
							uni.showLoading({
								title: '正在获取验证码'
							})
							send({
							mobile:this.mobile,
							        event:'login'	
							}).then((res)=>{
								setTimeout(() => {
									uni.hideLoading();
									// 通知验证码组件内部开始倒计时
									this.$refs.uCode.start();
								}, 1000);
							})
						
						}else {
							this.$u.toast('倒计时结束后再发送');
						}
					}
				
				}
		},
		onLoad() {
			let a =uni.getSystemInfoSync()
			console.log(a)
			
			console.log(a.deviceId)
			// tj({}).then((res)=>{
			// 	console.log(res)
			// })
			getXcxurl({
				page:"/pages/newindex/newindex",
				appid:"wx8b15dc2c1ee47c1f",
				query:'',
				expire_interval:'30'
			}).then((res)=>{
				console.log(res)
			})
  if(uni.getStorageSync('phone')){
	  wx.navigateTo({
	    url: `plugin://kdPlugin/index?pt=923091401&phone=`+uni.getStorageSync('phone')+`&env=master`
	  })
  }
	


                
		},
		watch: {

		},
		computed: {

		}
	}
</script>

<style scoped lang='scss'>
	.top{
		padding:10rpx
	}
</style>